Move initial stack-pointer adjustment into assembly
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 30 Dec 2005 16:02:30 +0000 (17:02 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Fri, 30 Dec 2005 16:02:30 +0000 (17:02 +0100)
bootstrap code. Avoids need for indirection thru
reset_stack_and_jump() in C code (which was incorrect for
secondary CPUs since nothing was pushed on the stack on
that initial call, hence the masking operation had no
effect and we ended up running on a bogus stack pointer).

Signed-off-by: Keir Fraser <keir@xensource.com>
xen/arch/x86/boot/x86_32.S
xen/arch/x86/boot/x86_64.S
xen/arch/x86/setup.c
xen/arch/x86/smpboot.c

index d510c1fa1b210b27621f46799545e45f613a2d02..b98e1c72bca0368d120bb76b4c9a59d7c84bb8a5 100644 (file)
@@ -1,5 +1,6 @@
 #include <xen/config.h>
 #include <public/xen.h>
+#include <asm/asm_defns.h>
 #include <asm/desc.h>
 #include <asm/page.h>
 #include <asm/msr.h>
@@ -53,6 +54,7 @@ __start:
         mov     %ecx,%gs
         ljmp    $(__HYPERVISOR_CS),$(1f)-__PAGE_OFFSET
 1:      lss     stack_start-__PAGE_OFFSET,%esp
+        add     $(STACK_SIZE-CPUINFO_sizeof-__PAGE_OFFSET),%esp
 
         /* Reset EFLAGS (subsumes CLI and CLD). */
        pushl   $0
@@ -167,7 +169,7 @@ no_execute_disable:
         lidt    idt_descr
                 
         cmp     $(SECONDARY_CPU_FLAG),%ebx
-        je      init_secondary
+        je      start_secondary
 
         /* Call into main C routine. This should never return.*/
                call    __start_xen
@@ -189,7 +191,7 @@ ignore_int:
 /*** STACK LOCATION ***/
         
 ENTRY(stack_start)
-        .long cpu0_stack + STACK_SIZE - __PAGE_OFFSET
+        .long cpu0_stack
         .long __HYPERVISOR_DS
         
 /*** DESCRIPTOR TABLES ***/
index d89b7bf51a663288774f31e0884207c3e4aa64d5..3ab012aad84b3328021e04358763b22b42c8db76 100644 (file)
@@ -1,5 +1,6 @@
 #include <xen/config.h>
 #include <public/xen.h>
+#include <asm/asm_defns.h>
 #include <asm/desc.h>
 #include <asm/page.h>
 #include <asm/msr.h>
@@ -121,7 +122,8 @@ skip_boot_checks:
         mov     %rcx,%cr4
 
         mov     stack_start(%rip),%rsp
-        
+        or      $(STACK_SIZE-CPUINFO_sizeof),%rsp
+
         /* Reset EFLAGS (subsumes CLI and CLD). */
         pushq   $0
         popf
@@ -140,9 +142,9 @@ __high_start:
         mov     %ecx,%ss
 
         lidt    idt_descr(%rip)
-                
+
         cmp     $(SECONDARY_CPU_FLAG),%ebx
-        je      init_secondary
+        je      start_secondary
 
         /* Initialize BSS (no nasty surprises!) */
         lea     __bss_start(%rip),%rdi
@@ -219,7 +221,7 @@ idt:
         .quad   idt_table
 
 ENTRY(stack_start)
-        .quad   cpu0_stack + STACK_SIZE
+        .quad   cpu0_stack
 
 high_start:
         .quad   __high_start
index f39a43c185a92d31b027bb504fbd4b2e9bc13a2e..38fb25d16ef3ae819ae693dd63163bf9b0401d47 100644 (file)
@@ -142,9 +142,7 @@ static void __init do_initcalls(void)
 
 static struct e820entry e820_raw[E820MAX];
 
-static multiboot_info_t *mbi;
-
-void __init start_of_day(void)
+void __init __start_xen(multiboot_info_t *mbi)
 {
     unsigned long vgdt, gdt_pfn;
     char *cmdline;
@@ -561,12 +559,6 @@ void __init start_of_day(void)
     startup_cpu_idle_loop();
 }
 
-void __init __start_xen(multiboot_info_t *__mbi)
-{
-    mbi = __mbi;
-    reset_stack_and_jump(start_of_day);
-}
-
 void arch_get_xen_caps(xen_capabilities_info_t info)
 {
     char *p = info;
index 96117b0727e0f02be78af76d929d87f9a521153d..30ca4864b23e4402f8458eba230a4e64a8af9f80 100644 (file)
@@ -429,7 +429,7 @@ static void construct_percpu_idt(unsigned int cpu)
 /*
  * Activate a secondary processor.
  */
-void __init start_secondary(void)
+void __init start_secondary(void *unused)
 {
        unsigned int cpu = cpucount;
 
@@ -472,11 +472,6 @@ void __init start_secondary(void)
        startup_cpu_idle_loop();
 }
 
-void __init init_secondary(void)
-{
-    reset_stack_and_jump(start_secondary);
-}
-
 extern struct {
        void * esp;
        unsigned short ss;
@@ -768,7 +763,6 @@ static int __init do_boot_cpu(int apicid)
 {
        struct domain *idle;
        struct vcpu *v;
-       void *stack;
        unsigned long boot_error;
        int timeout, cpu;
        unsigned long start_eip;
@@ -791,15 +785,10 @@ static int __init do_boot_cpu(int apicid)
        /* So we see what's up   */
        printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
 
-       stack = alloc_xenheap_pages(STACK_ORDER);
-#if defined(__i386__)
-       stack_start.esp = (void *)__pa(stack) + STACK_SIZE;
-#elif defined(__x86_64__)
-       stack_start.esp = stack + STACK_SIZE;
-#endif
+       stack_start.esp = alloc_xenheap_pages(STACK_ORDER);
 
        /* Debug build: detect stack overflow by setting up a guard page. */
-       memguard_guard_stack(stack);
+       memguard_guard_stack(stack_start.esp);
 
        /*
         * This grunge runs the startup process for